from django.shortcuts import render
from rest_framework.mixins import CreateModelMixin,ListModelMixin,RetrieveModelMixin
from rest_framework.viewsets import GenericViewSet
from .models import Patient
from utils.common_response import APIResponse
from .serializer import PatientPostSer,PatientGetSer
from registered.pagination import MyPagination
from .out_filter import MyFilter
# Create your views here.


# 诊断 结果 录入
class PatientPostVue(CreateModelMixin, GenericViewSet):
    queryset = Patient.objects.all()
    serializer_class = PatientPostSer

    def create(self, request, *args, **kwargs):
        res = super().create(request, *args, **kwargs)
        print(res)
        return APIResponse(data=res.data)


class PatientGetVue(ListModelMixin, RetrieveModelMixin, GenericViewSet):
    queryset = Patient.objects.all()
    serializer_class = PatientGetSer
    pagination_class = MyPagination
    filter_backends = [MyFilter, ]

    def list(self, request, *args, **kwargs):
        res = super().list(request, *args, **kwargs)
        return APIResponse(infos=res.data)

    def retrieve(self, request, *args, **kwargs):
        res = super().retrieve(request, *args, **kwargs)
        return APIResponse(info=res.data)